﻿using System;
using System.Collections.Generic;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL
{
    /// <summary>
    /// 品牌字典操作类
    /// </summary>
    public class DicBrandBean
    {
        /// <summary>
        /// 获取所有品牌字典数据
        /// </summary>
        /// <returns></returns>
        public IList<DicBrand> GetAllBrand()
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.DicBrand).ToList<DicBrand>();
        }

        /// <summary>
        /// GetBrand
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DicBrand GetBrand(int id)
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.DicBrand).Where(
                GoShoppingNBear.DicBrand.ID == id
                ).ToSingleObject<DicBrand>();
        }

        /// <summary>
        /// 添加一个品牌
        /// </summary>
        /// <param name="brand"></param>
        /// <returns></returns>
        public bool AddDicBrand(string brand)
        {
            int i = Databases.DBGoShopping.Select(GoShoppingNBear.DicBrand, GoShoppingNBear.DicBrand.ID.Count()).Where(
                GoShoppingNBear.DicBrand.Name == brand).ToScalar<int>();
            if (i > 0)
            {
                return false;
            }
            i = Databases.DBGoShopping.Insert(
                GoShoppingNBear.DicBrand).AddColumn(
                GoShoppingNBear.DicBrand.Name, brand).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一个品牌
        /// </summary>
        /// <param name="dicBrandID"></param>
        /// <returns></returns>
        public bool DelDicBrand(int dicBrandID)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.DicBrand).Where(
                GoShoppingNBear.DicBrand.ID == dicBrandID).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一个品牌
        /// </summary>
        /// <param name="brandName"></param>
        /// <returns></returns>
        public bool DelDicBrandByName(string brandName)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.DicBrand).Where(
               GoShoppingNBear.DicBrand.Name == brandName).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
